//
//  AppDelegate.swift
//  maopu
//
//  Created by 黄海波 on 2017/4/1.
//  Copyright © 2017年 maopu. All rights reserved.
//

import UIKit

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
    
    var blockRotation: Bool = false
    var window: UIWindow?
    var tabbarController:MainTabBarController!

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
        
        self.window = UIWindow(frame: UIScreen.main.bounds)
        tabbarController = MainTabBarController()
        self.window?.rootViewController = tabbarController
        self.window!.makeKeyAndVisible()
        self.initializePlat()
        return true
    }
    
    func application(_ application: UIApplication, supportedInterfaceOrientationsFor window: UIWindow?) -> UIInterfaceOrientationMask {
        if self.blockRotation{
            return .allButUpsideDown
        }else{
            return .portrait
        }
    }

    func applicationWillResignActive(_ application: UIApplication) {
        
    }

    func applicationDidEnterBackground(_ application: UIApplication) {
        
    }

    func applicationWillEnterForeground(_ application: UIApplication) {
        
    }

    func applicationDidBecomeActive(_ application: UIApplication) {
        
    }

    func applicationWillTerminate(_ application: UIApplication) {
        
    }
    func initializePlat() {
        //1.初始化ShareSDK应用http://www.mob.com/后台申请的ShareSDK应用的Appkey [WeiboSDK class]
//        ShareSDK.registerApp("10aca83547094")
//        ShareSDK.connectWeChat(withAppId: "wx2b1d0b3fb6b0866a", wechatCls: WXApi.self)
//        WXApi.registerApp("wx2b1d0b3fb6b0866a")
//        ShareSDK.ssoEnabled(true)
        ShareSDK.registerApp("10aca83547094",
                             activePlatforms :
            [
                SSDKPlatformType.typeQQ.rawValue,
                SSDKPlatformType.typeWechat.rawValue,
                SSDKPlatformType.subTypeQQFriend.rawValue,
                SSDKPlatformType.typeSinaWeibo.rawValue,
            ],
           // onImport 里的代码,需要连接社交平台SDK时触发
            onImport: {(platform : SSDKPlatformType) -> Void in
                switch platform
                {
                case SSDKPlatformType.typeSinaWeibo:
                    ShareSDKConnector.connectWeibo(WeiboSDK.classForCoder())
                case SSDKPlatformType.typeWechat:
                    ShareSDKConnector.connectWeChat(WXApi.classForCoder())
                case SSDKPlatformType.typeQQ:
                    ShareSDKConnector.connectQQ(QQApiInterface.classForCoder(), tencentOAuthClass: TencentOAuth.classForCoder())
                default:
                    break
                }
        },
            onConfiguration: {(platform : SSDKPlatformType , appInfo : NSMutableDictionary?) -> Void in
                switch platform
                {
                case SSDKPlatformType.typeSinaWeibo:
                    //设置新浪微博应用信息,其中authType设置为使用SSO＋Web形式授权
                    appInfo?.ssdkSetupSinaWeibo(byAppKey: "1316874686",
                                                appSecret: "7d721da6d71192319557284ed78ad7e0",
                                                redirectUri: "http://www.daoyoutalk.com",
                                                authType: SSDKAuthTypeBoth)
                    
                case SSDKPlatformType.typeWechat:
                    //设置微信应用信息
                    appInfo?.ssdkSetupWeChat(byAppId: "wx2b1d0b3fb6b0866a",
                                             appSecret: "96d198a09c616b1460ee3cbf92d0e7be")
                    
                case SSDKPlatformType.typeQQ:
                    //设置QQ应用信息
                    appInfo?.ssdkSetupQQ(byAppId: "1105037376",
                                         appKey: "Y58K6DuWRKa9J2Dr",
                                         authType: SSDKAuthTypeWeb)
                    
                    

                default:
                    break
                }
        })

    }
}
